﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Code.Models;

namespace Code.BLL
{
    public class BackMoneyTypeManage : ManageBase<BackMoneyType>
    {
        public int InsertData(string name)
        {
            BeginTransaction();
            base.Insert(new { name });
            base.Execute(new SqlExpression(@"declare @id int 
    set @id=@@identity
	insert into BackMoney_Site(LotteryID,WinModelID,BackMoneyTypeID,BackMoney)
	select l.ID,w.ID,@id,0 from Lottery as l  inner join  WinMoneyModel as w on 1=1 "));
            int rs = base.ExecuteTransaction();
            CacheManage.IsLoadBackMoneyType = true;
            return rs;
        }

        public int Edit(int id, string name)
        {
            int rs = base.Update(new { Name = name }, new { ID = id });
            CacheManage.IsLoadBackMoneyType = true;
            return rs;
        }

        public int Del(params int[] ids)
        {
            base.BeginTransaction();
            base.Delete<BackMoney_User>(new { BackMoneyTypeID = new ComparValue(Comparison.In, ids) });
            base.Delete<BackMoney_Site>(new { BackMoneyTypeID = new ComparValue(Comparison.In, ids) });
            base.Delete(new { ID = new ComparValue(Comparison.In, ids) });
            int rs = base.ExecuteTransaction();
            CacheManage.IsLoadBackMoneyType = true;
            return rs;
        }
    }
}
